package com.client.ryt.basic;

import com.client.ryt.entity.exception.JsonException;
import com.client.ryt.entity.exception.RemoteDataException;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by zzyang on 2014-07-08.
 */
public class BaseResponse {
    public BaseResponse(JSONObject json){
        if(json != null) {
            if (json.has("status") && json.has("msg")) {
                try {
                    this.status = json.getInt("status");
                    if (this.status == 0) {
                        this.isSuccess = true;
                    } else {
                        this.isSuccess = false;
                        this.baseException = new RemoteDataException(json);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }else{
                this.isSuccess = false;
                this.baseException = new BaseException(BaseException.ExceptionType.REMOTEDATA_ERR,"数据格式不正确");
            }
        }
    }



    private Boolean isSuccess = false;
    private int status;
    private BaseException baseException;

    public Boolean getIsSuccess() {
        return isSuccess;
    }

    public void setIsSuccess(Boolean isSuccess) {
        this.isSuccess = isSuccess;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public BaseException getBaseException() {
        return baseException;
    }

    public void setBaseException(BaseException baseException) {
        this.baseException = baseException;
    }
}
